package com.fast.admin.controller;

import com.fast.admin.common.utils.ShiroUtil;
import com.fast.common.util.PageUtil;
import com.fast.common.util.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.*;

/**
 * @Title：测试控制器
 * @author：ylc
 * @date：2018/7/12 17:19
 * @version：1.0
 **/
@Controller
@Slf4j
@RequestMapping(value = "/test")
public class TestController {

    @GetMapping(value = "index")
    public String index(){
        return "index";
    }

    @GetMapping(value = "print")
    @ResponseBody
    public Map<String, Object> print(){
        Map<String, Object> map = new HashMap<>();
        map.put("time", Calendar.getInstance().getTime());
        map.put("s","aha哈哈");
        return map;
    }

    @GetMapping(value = "table")
    public String table(){
        return "table";
    }

    @GetMapping(value = "json")
    @ResponseBody
    public R json() throws IOException {

        Map<String, Object> map = new HashMap();
        List<Map<String, Object>> list = new ArrayList<>();
        map.put("id", 11);
        map.put("username", "哈哈哈");
        list.add(map);
        PageUtil pageUtil = new PageUtil(50L, list);
        return R.ok(pageUtil);
    }

    @GetMapping(value = "form")
    public String form(){
        return "group";
    }

    @PostMapping(value = "add")
    @ResponseBody
    public R insert( String name, String url, String pId){
        log.info("name:============  "  + name);
        log.info("url:============  "  + url);
        log.info("PID:============  "  + pId);
        return R.ok();
    }

    @GetMapping("treeTable")
    public String treeTable(){
        return "treeTable";
    }


    @GetMapping("set")
    @ResponseBody
    public Object set(){
        ShiroUtil.setSession("userTest", "ylc");
        return "success";
    }

    @GetMapping("get")
    @ResponseBody
    public Object get(){
        return ShiroUtil.getSession("userTest");
    }
}
